package com.javatom.notes.feign.web;


import com.javatom.notes.common.User;
import com.javatom.notes.common.model.BaseResponse;
import com.javatom.notes.feign.service.FeignMongoOperatService;
import com.javatom.notes.feign.service.UserFeignOperatService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/iuser")
@Slf4j
/**
 * 采用Feign调用内部服务
 */
public class FeignUserOperatControllor {
    @Resource
   private UserFeignOperatService userFeignOperatService;
   @Value("${spring.application.name}")
   private String applicationName;
    @Value("${server.port}")
    private String port;
  //  @ApiOperation(value = "测试mongo批量插入数据")
   @RequestMapping(value = {"/getUser"}, method = {RequestMethod.GET})
   public BaseResponse<User> getUser() {
       log.error("applicationName {}",applicationName);
       User user = User.createUser();
       user.setId(32);
       BaseResponse<User> a=  userFeignOperatService.getUser(user);
       log.error("initData {}",a);
      return a;
   }
    @RequestMapping(method = RequestMethod.GET, value = "/list")
    BaseResponse<List<User>> getList(){
       return userFeignOperatService.getList();
    }

    /**
     * Post 示例
     * @param userId

     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/user/{userId}")
    BaseResponse<User> update(@PathVariable("userId") Integer userId){
        return userFeignOperatService.update(userId,User.createUser());
    }

}
